package com.mach.platform.repository;

import com.mach.platform.domain.DevFollow;
import com.mach.platform.domain.base.Account;
import com.mach.platform.domain.iot.IotDev;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.beans.Transient;
import java.util.List;

/**
 * @author Administrator
 * @Description:
 * @Package: com.mach.platform.repository
 * @time 2018/7/20 0020 11:04
 */
@Repository
public interface DevFollowRepo extends BaseRepository<DevFollow> {

	/**
	 *  获取 对应用户 的  设备 关注数据
	 * @param account
	 * @return
	 */
	List<DevFollow> getAllByUser (Account account);

	/**
	 *  取消关注，删除数据
	 * @param dev
	 * @param account
	 */
	int deleteByDeviceAndUser (IotDev dev, Account account);

	/**
	 * 查找
	 * @param dev
	 * @param account
	 * @return
	 */
	DevFollow findByDeviceAndUser (IotDev dev, Account account);

	/**
	 * 删除设备数据后，删除所有关于该设备的关联
	 * @param iotDev
	 * @return
	 */
	int deleteDevFollowsByDevice (IotDev iotDev);


	/**
	 * 删除设备数据后,删除空间关联关系
	 * @param id
	 * @return
	 */
	@Modifying
	@Transactional
	@Query(value = "delete from energy_struc_prop where dev_id = ?1",nativeQuery = true)
	int deleteEnergyStrucPropByDevId(Long id);
}
